(function($) {
    let started = false, gluttonRecorder;

    function startRecording(traceNo) {
        if (! gluttonRecorder)
            throw new Error('GluttonRecorder还未创建');

        if (started) {
            $F.notify("GluttonRecorder已在录制过程中", -1);
        }
        started = true;
        if (arguments.length && window.GluttonContext)
            window.GluttonContext.traceNo = traceNo;
        gluttonRecorder.startRecord();
    }

    function stopRecording() {
        if (! gluttonRecorder)
            throw new Error('GluttonRecorder还未创建');

        if (! started) {
            $F.notify("GluttonRecorder未启动录制", -1);
        }
        gluttonRecorder.stopRecord();
    }

    window.Glutton = {
        init(options) {
            gluttonRecorder = new GluttonRecorder(options);
        },

        start(traceNo) {
            startRecording(traceNo);
        },

        stop() {
            stopRecording()
        },

        attr(key, value) {
            window.GluttonContext.key = value;
        }

    }
})(jQuery)
